﻿@using A2.ERP.Models
@{
    List<p_Inventory_getSearchList_Result> GetSearchLists = ViewBag.GetSearchList;
}
@{
    Layout = null;
}

<div id="ManagerInventory">
    <div class="card">
        <div class="card-body">
            <div class="row">
                <div class="col-sm">
                    <div class="input-group mb-3" style="width: 200px">
                        <div class="input-group-prepend">
                            <span class="input-group-text">单据编号
                            </span>
                        </div>
                        <input type="text" id="InventoryID" class="form-control" placeholder="Username" aria-label="Username" aria-describedby="basic-addon1">
                    </div>
                </div>
                <div class="col-sm">
                    <input type="date" id="StatTime" class="form-control" aria-label="Username" aria-describedby="basic-addon1">
                </div>
                <div class="col-sm">
                    <input type="date" id="EndTime" class="form-control" aria-label="Username" aria-describedby="basic-addon1">
                </div>
                <div class="col-sm">
                    <div class="input-group mb-3" style="width: 200px">
                        <div class="input-group-prepend">
                            <label class="input-group-text" for="inputGroupSelect01">状态</label>
                        </div>
                        <select class="custom-select" id="States">
                            <option value="0">全部</option>
                            <option value="1">未审</option>
                            <option value="2">已审</option>
                        </select>
                    </div>
                </div>
                <div class="col-sm">
                    <button class="btn btn-primary btnSearch InventorySearch">
                        <i class="icon SkyUI icon-search"></i>
                        搜索
                    </button>
                    <button class="btn btn-primary">
                        <a data-route="/Store/InventoryModule">添加
                        </a>
                    </button>
                </div>
            </div>
        </div>
    </div>
    <table class="table table-bordered" style="text-align: center;">
        <thead>
            <tr>
                <th>单号</th>
                <th>商品</th>
                <th>盘点库区</th>
                <th>账面数量</th>
                <th>实际数量</th>
                <th>日期</th>
                <th>状态</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var item in GetSearchLists)
            {
                <tr>
                    <td>@item.InventoryID
                    </td>
                    <td>@item.ProductsName</td>
                    <td>@item.HouseName
                        --
                        @item.SubareaName
                    </td>
                    <td>@item.RealityNum</td>
                    <td>@item.AdjustNum</td>
                    <td>@item.CreateDate</td>
                    <td>
                        @Html.Raw(item.State.ToString() == "1"
                           ? @"<i class='icon SkyUI icon-check-circle text-success'></i>"
                           : @"<i class='icon SkyUI icon-close-circle text-danger'></i>")
                    </td>
                    <td>
                        <button data-id="@item.InventoryID" class="btn btn-sm btn-danger btn-delGroup" data-target="#delGroupModal" data-toggle="modal" >删除</button>

                        <button data-id="@item.InventoryID" data-state="@item.State"   class="btn btn-sm btn-primary btn-updateGroup" data-target='#AuditModal' data-toggle='modal' >
                           @Html.Raw(item.State.ToString() == "1"
                           ? @"禁用"
                           : @"审核")
                        </button>
                    </td>
                </tr>
            }
        </tbody>
    </table>

    <div class="modal fade" id="delGroupModal" tabindex="-1" role="dialog" aria-labelledby="sysUserModalLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">确定要删除该盘点吗？</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    确定要删除?
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary btn-sureDelGroup">确定</button>
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="AuditModal" tabindex="-1" role="dialog" aria-labelledby="sysUserModalLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title">确定要通过对该产品的审核</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    确定通过？
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-primary btn-AuditGroup">确定</button>
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                </div>
            </div>
        </div>
    </div>
    <script>
        var $btnSearch = $('.btnSearch');

        var $btnDelGroup = $('.btn-delGroup');//删除按钮

        var $AuditGroup = $('.btn-updateGroup');//审核修改

        var $delete = $('.btn-sureDelGroup');//确定删除

        var $update = $('.btn-AuditGroup')//确定修改

        var $InventorySearch = $(".InventorySearch");

        var SearchId = null;//获取id的值

        var State = null

        //点击删除按钮时获取到id
        $btnDelGroup.on('click', function () {

            SearchId = $(this).attr('data-id');

        });

        $AuditGroup.on('click', function () {

            SearchId = $(this).attr('data-id');

            State = $(this).attr('data-state');
        });

        //删除
        $delete.on('click', function () {
            $.ajax({
                url: '/Repertory/DeleteEitity',
                dataType: 'json',
                type: 'DELETE',
                data: { id: SearchId },
                success: function (data) {
                    $('.modal').modal('hide');

                    if (data) {
                        $tab.reloadTab('#ManagerInventory');
                    }
                    else {
                        console.log(data);
                    }
                }
            });
        });
        //审核
        $update.on('click', function () {
            $.ajax({
                url: '/Repertory/UpdateInventory',
                dataType: 'json',
                type: 'POST',
                data: {
                    id: SearchId,
                    state: State
                },
                success: function (data) {
                    $('.modal').modal('hide');

                    if (data) {
                        $tab.reloadTab('#ManagerInventory');
                    }
                    else {
                        console.log(data);
                    }
                }
            });
        });

        //查询
        $InventorySearch.on('click', function (e) {
            //return;
            $tab.reloadTab('#ManagerInventory', [
                { InventoryID: $('#InventoryID').val() },
                { beginDate: $('#StatTime').val() },
                { endDate: $('#EndTime').val() },
                { sideState: $('#States').val() }
            ]);
        });
    </script>
</div>

